﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace Nirvana
{
    [AddComponentMenu("Nirvana/UI/Bind/Event Bind Press Down")]
    public sealed class UIEventBindPressDown : UIEventBind, IPointerDownHandler
    {
        [EventName]
        [SerializeField]
        private string eventName;
        private Selectable _selectable;
        private SignalEvent _signalevent;

        protected override void Awake()
        {
            base.Awake();
            this._selectable = base.GetComponent<Selectable>();
        }

        protected override void RefreshBind()
        {
            this._signalevent = base.GetSignalEvent(this.eventName);
        }

        public void OnPointerDown(PointerEventData eventData)
        {
            if (this._selectable != null && !this._selectable.interactable)
            {
                return;
            }
            SignalEvent _event = this.FindSignalEvent();
            if (_event != null)
            {
                _event.Excute();
            }
        }

        private SignalEvent FindSignalEvent()
        {
            if (this._signalevent == null)
            {
                this._signalevent = base.GetSignalEvent(this.eventName);
            }
            return this._signalevent;
        }

    }
}

